package com.e3.basdoc.region.client;

import java.util.ArrayList;
import java.util.List;

import com.e3.basdoc.region.model.RegionModel;
import com.e3.basdoc.region.model.RegionQC;
import com.e3.template.tgf.TGFQueryDialog;
import com.e3.web.core.client.GwtAsyncCallback;
import com.e3.web.core.model.SuperQC;
import com.e3.web.widget.client.MyField;
import com.extjs.gxt.ui.client.widget.form.Field;

public class RegionQueryDialog extends TGFQueryDialog<RegionModel> {

	@Override
	protected List<Field<?>> getFormFields() {
		String[] names = { RegionModel.CODE, RegionModel.NAME, RegionModel.ENGLISH_NAME };
		List<Field<?>> fields = new ArrayList<Field<?>>();

		for (String name : names) {
			Field<?> formField = RegionHelper.INSTANCE.createFormField(name);
			fields.add(formField);
		}

		return fields;
	}

	@Override
	protected SuperQC getQueryCondition() {
		MyField<?> field = getMyFormField(RegionModel.CODE);
		String code = (String) field.getFieldValue();
		field = getMyFormField(RegionModel.NAME);
		String name = (String) field.getFieldValue();
		field = getMyFormField(RegionModel.ENGLISH_NAME);
		String englishName = (String) field.getFieldValue();

		RegionQC qc = new RegionQC();
		qc.setCode(code);
		qc.setName(name);
		qc.setEnglishName(englishName);
		return qc;
	}

	@Override
	protected void executeQueryService(SuperQC qc,GwtAsyncCallback<List<RegionModel>> callback) {
		//service.getRegionsByCondition((RegionQC)qc, getQueryAsyncCallBack(qc));
		onQuerySuccess(qc, null);
	}

}
